/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbean;

import bean.session.ConvertedCustomerEntityFacade;
import entity.ConvertedCustomerEntity;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

/**
 *
 * @author AdminNUS
 */
@ManagedBean(name="exportToPDFBean")
//@Named(value = "exportToPDFBean")
@RequestScoped
public class ExportToPDFBean {

    
    @EJB
    private bean.session.ConvertedCustomerEntityFacade facade;

    public ConvertedCustomerEntityFacade getFacade() {
        return facade;
    }

    public void setFacade(ConvertedCustomerEntityFacade facade) {
        this.facade = facade;
    }
    /** Creates a new instance of ExportToPDFBean */
    public ExportToPDFBean() {
    }
    
    public void printConvertedCustomer() throws IOException, JRException {
    ConvertedCustomerEntityFacade ccEntityFacade = new ConvertedCustomerEntityFacade();
        //SalesLeadEntityFacade slEntityFacade = new SalesLeadEntityFacade(); 

    List<ConvertedCustomerEntity> cc = getFacade().getConvertedCustomerEntity();
    //List<SalesLeadEntity> cc = slEntityFacade.getLockedUser();
    //cc.add(convertedCustomer);
    //for(ConvertedCustomerEntity c :cc)System.out.println(c.getSalesLeadCount() +"hhhhh");

    JRBeanCollectionDataSource datasource = new JRBeanCollectionDataSource(cc); 

    JasperReport jasperReport = JasperCompileManager.compileReport(System.getProperty("user.home")+"/Documents/NetBeansProjects/trunk/trunk/MacTeam/MacTeam-war/web/jasperreports/reportEmpty.jrxml");
    JasperPrint  jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), datasource);
    JasperExportManager.exportReportToPdfFile(jasperPrint, System.getProperty("user.home")+"/Documents/NetBeansProjects/trunk/trunk/MacTeam/dist/gfdeploy/MacTeam/MacTeam-war_war/jasperreports/testReportEmpty.pdf");
    System.out.println("********" + FacesContext.getCurrentInstance().getExternalContext().getRealPath("/"));
    FacesContext.getCurrentInstance().getExternalContext().redirect("/jasperreports/testReportEmpty.pdf");
}
}
